<template>
  <div class="search-wrapper">
      <template v-if="no_search">
          <button title="显示列表"   class="ui button tiny" @click.stop.prevent="doSearch">显示列表</button>
      </template>
      <template v-else>

          <span v-if="useModal">
          <button title="搜索"   class="ui button tiny" @click.stop.prevent="showSearchModal">搜索</button>
        <button title="显示列表"   class="ui button tiny" @click.stop.prevent="doSearch">显示列表</button>
        </span>

              <div class="ui action input" v-else>
                  <input type="text" v-model.trim="con" placeholder="请输入搜索内容" @keyup.enter.stop.prevent="doSearch">
                  <button type="button" class="ui button" @click.stop.prevent="doSearch">搜索</button>
                  <button type="button" class="ui button icon" @click.stop.prevent="clearSearch">
                      <i class="icon remove"></i>
                  </button>
              </div>

      </template>

  </div>
</template>

<script>
  import tool from 'src/util/tool';
  import util from '_util/index';
  import logic from '_logic';

  export default {
    data() {
      return {
        con: '',
        is_all: false
      }
    },
    computed: {
      clearAttrStr() {
        return 'clearAttr_' + this.name
      },
      not_use_modal() {

      },
        ctl() {
            return this.$route.query.ctl;
        },
      useModal() {
          let not_useModal = logic.search.get_not_useModal(this);
          if(not_useModal)
            return false;
          return this.bind_mid && !util.store.get(this, 'in_modal');
      }
    },
    methods: {
      showSearchModal() {
        let modal_search_mid = util.store.get(this, 'modal_search_mid');
//        if(modal_search_mid&&modal_search_mid!=this.bind_mid)
        if(modal_search_mid)
          util.eventEmit(this, 'changeSearch',this.bind_mid,this.name);
        util.eventEmit(this, 'showSearchModal');
      },
      clearSearch() {
          this.con = '';
        this.$emit('clearSearch')
      },
      doSearch() {
        util.store.commit(this,'setSearchLoader', true);
        let url = this.url
        let param = {};
        let con = this.con
        if (con) {
          param.con = con;
          param.stype = 2;
//          param.isSearch = 1;
//          param.is_search = 1;
        }
        // param.notParse = 1;
//        tool.cl(url, param);
        this.$emit('doBindSearch', url, param)
      }
    },
    watch: {},
    props: ['url', 'name', 'bind_mid','no_search']
  };
</script>

<style rel="stylesheet/less" scoped lang="less">
  .search-wrapper {
  }
</style>
